package models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import play.data.validation.MaxSize;
import play.data.validation.Required;
import play.db.jpa.GenericModel;

@Entity
@Table(name = "medicine_card")
public class MedicineCard extends GenericModel {

    @Id
    @Column(name = "medicine_card_id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long medicineCardId;

    @Required
    @Column(name = "creation_date")
    public Date creationDate;

    @MaxSize(10000)
    @Column(name = "other_info")
    public String otherInfo;

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
		+ ((creationDate == null) ? 0 : creationDate.hashCode());
	result = prime * result
		+ ((medicineCardId == null) ? 0 : medicineCardId.hashCode());
	result = prime * result
	+ ((otherInfo == null) ? 0 : otherInfo.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	MedicineCard other = (MedicineCard) obj;
	if (creationDate == null) {
	    if (other.creationDate != null)
		return false;
	} else if (!creationDate.equals(other.creationDate))
	    return false;
	if (medicineCardId == null) {
	    if (other.medicineCardId != null)
		return false;
	} else if (!medicineCardId.equals(other.medicineCardId))
	    return false;
	if (otherInfo == null) {
	    if (other.otherInfo != null)
		return false;
	} else if (!otherInfo.equals(other.otherInfo))
	    return false;
	return true;
    }

    @Override
    public String toString() {
	return "MedicineCard [medicineCardId=" + medicineCardId + "," + 
	                    " creationDate=" + creationDate + "," + 
	                    " otherInfo=" + otherInfo + "]";
    }

}
